package com.sam.thread.demo4;

/**
 * Created by SamZhao on 2017/5/29.
 */
public class Output implements  Runnable {

    private Resource resource ;

    public Output(Resource resource) {
        this.resource = resource;
    }

    @Override
    public void run() {
        while(true){
            synchronized (resource) {
                if(resource.flag == false){
                    try {
                        resource.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }else{
                    System.out.println(resource.toString());
                    resource.flag = false;
                    resource.notify();
                }
            }
        }
    }
}
